package com.example.owner.lettery1.other

import com.example.owner.lettery1.bean.Champion
import com.example.owner.lettery1.bean.Record
import com.example.owner.lettery1.modlus.NewsApi
import com.example.owner.lettery1.modlus.RetrofitClient
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class ChampionPresenter {

    fun getChampionInfo(lotId: String, issue: String): Observable<Champion> {
        val api = RetrofitClient.createService(NewsApi::class.java)
        val callback = api.getChampionInfo("1", lotId, issue)
        return callback.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map { data ->
                    return@map data.datas!!
                }
    }

    fun getChampionList(lotteryId: String, pageIndex: Int): Observable<ArrayList<Record>> {
        val api = RetrofitClient.createService(NewsApi::class.java)
        val callback = api.getRecents(lotteryId, "20", pageIndex, "1")
        return callback.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map { data ->
                    if (data.datas != null || data.datas!!.isNotEmpty()) {
                        return@map data.datas!!
                    }
                    return@map ArrayList<Record>()
                }
    }
}